package com.example.user1.vo;

import lombok.Getter;
import lombok.experimental.Accessors;

import java.util.List;

@Getter
@Accessors(chain = true)
public class PageResult<T> {

    private int pageNo;

    private int pageSize;

    private int total;

    private List<T> records;

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    private void setTotal(int total) {
        this.total = total;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    public static <T> PageResultBuilder<T> builder(){
       return new PageResultBuilder<>();
    };


    public static class PageResultBuilder<T>{
        private PageResult<T> pageResult;
        PageResultBuilder(){
            pageResult = new PageResult<T>();
        }

        public PageResultBuilder<T> setPageNo(int pageNo){
            pageResult.setPageNo(pageNo);
            return this;
        }
        public PageResultBuilder<T> setPageSize(int pageSize){
            pageResult.setPageSize(pageSize);
            return this;
        }

        public PageResultBuilder<T> setTotal(int total){
            pageResult.setTotal(total);
            return this;
        }
        public PageResultBuilder<T> setRecords(List<T> records){
            pageResult.setRecords(records);
            return this;
        }

        public PageResult<T> build(){
            return pageResult;
        }
    }
}
